{% extends "template/layout.html" %} {% block content %}
<style>
    .settingPanel {
        margin: 30px;
    }

    .addressInput {
        width: 350px;

    }

    .companyBtn {
        float: right;
    }
    .downbtn{
        margin-top:-10px;
    }
</style>

<div class="panel panel-default settingPanel">
    <div class="layui-collapse">
        <div class="layui-colla-item">
            <h2 class="layui-colla-title">公司信息设置</h2>
            <div class="layui-colla-content layui-show">
                <form class="layui-form" lay-filter="companyForm">


                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">公司名:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">公司地址:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="address" lay-verify="required" autocomplete="off" class="layui-input addressInput ">
                            </div>
                        </div>


                        <div class="layui-inline  companyBtn">
                            <button class="layui-btn" lay-submit="" lay-filter="companyEdit">提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <div class="layui-colla-item">
            <h2 class="layui-colla-title">数据备份设置</h2>
            <div class="layui-colla-content layui-show">
                <div class="layui-input-inline">
                <form class="layui-form" lay-filter="sqlForm">
                    <div class="layui-form-item">
                        <div class="layui-inline">

                            <label class="layui-form-label">自动备份：</label>
                            <div class="layui-input-inline">
                                <input type="checkbox" name="close" lay-skin="switch" lay-text="ON|OFF" lay-filter="switchBackup">
                            </div>

                        </div>
                       


                    
                    </div>

                </form>
            </div>
                <div class="layui-inline  downbtn">
                        <div class="layui-input-inline">
                                <button class="layui-btn   " lay-submit=""  lay-filter="downSql" > 立即下载 </button>       
                         </div>
                    </div>
            
            </div>
        </div>
    </div>
</div>


{% endblock %} {% block footer %}
<script>
    var detailformData = {}; //获取渲染的数据
    detailformData.address = `{{getCompany.address}}`;
    detailformData.id = `{{getCompany.id}}`;
    detailformData.name = `{{getCompany.name}}`;
    var backupFormData ={};
    backupFormData.id =`{{getBackupStatus.id}}`;
    backupFormData.backupStatus =`{{getBackupStatus.backupStatus}}`;
    backupFormData.sqlUrl = `{{getBackupStatus.url}}`;
    backupFormData.close =true;
    if( backupFormData.backupStatus==0){
        backupFormData.close =false;

    }

    layui.use(['form', 'layedit', 'laydate', 'element'], function () {
        var element = layui.element;
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;

        form.val('companyForm', detailformData); //填充公司信息表格
        form.val('sqlForm',backupFormData); //填充数据备份设置信息
        //监听公司信息提交事件
        form.on('submit(companyEdit)', function (data) {
            var formData = data.field;
            formData.id = detailformData.id;
            $.post('/setting/company', formData, function (res) {
                if (res.status != 200) {
                    layer.open({
                        title: '警告',
                        content: res.msg,
                        icon: 2,
                        skin: 'layer-ext-moon',
                        closeBtn: 0
                    });
                    return;

                } else {
                    layer.alert("编辑成功！")
                }
            })
            return false;
        })
   
   //监听数据备份开关事件
  form.on('switch(switchBackup)', function(data){
      var backupStatus= this.checked;
      $.post('/setting/backup',{backupStatus:backupStatus,backupId:backupFormData.id}, function(res){
        if(res.status!=200){
            layer.open({
                        title: '警告',
                        content: res.msg,
                        icon: 2,
                        skin: 'layer-ext-moon',
                        closeBtn: 0
                    });
                    return;  
        }
      })
    var  msg="数据库自动备份已关闭！"
      if(backupStatus){
        msg='数据库自动备份已开启！'
      }
   layer.tips('温馨提示：',msg);
  });
      //下载
      form.on('submit(downSql)',function(){
        window.location.href=  backupFormData.sqlUrl ;
      })
 

    });
</script>
{% endblock %}